package com.fone.player.online.adapter;

import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import com.fone.player.entity.LabelInfo;
import com.fone.player.online.fragment.ColumnFragment;
import com.fone.player.online.fragment.CommonFragment;
import com.fone.player.online.fragment.GridModeFragment;
import com.fone.player.online.fragment.HotFragment;
import com.fone.player.online.fragment.LeaderboardFragment;
import com.fone.player.online.fragment.LiveFragment;
import com.fone.player.online.fragment.SoftFragment;
import com.fone.player.online.fragment.VipFragment;

public class OnlineAdapter extends FragmentStatePagerAdapter {
	
	/** 日志标签 */
//	private static final String TAG = "OnlineAdapter";
	
	/**
	 * 08 4.0栏目模板-1（专题）
	 * 09 4.0栏目模板-2（直播）
	 * 10 4.0栏目模板-3（竖版）
	 * 11 4.0栏目模板-4（横版）
	 * 12 4.0栏目模板-5（通用）
	 * 13 4.0栏目模板-6（栏目首页）
	 * 14 4.0栏目模板-7（vip首页）
	 */

	/** 在线频道页模板类型 */
	private static final int CHANNEL_LIVE 			= 9;
	private static final int CHANNEL_VERTICAL 		= 10;
	private static final int CHANNEL_HORIZONTAL 	= 11;
	private static final int CHANNEL_COMMON 		= 12;
	private static final int CHANNEL_COLUMN 		= 13;
	private static final int CHANNEL_VIP 			= 14;
	private static final int CHANNEL_LEADERBOARD	= 16;
	
	private List<LabelInfo> tabsList;

	public OnlineAdapter(FragmentManager fm, List<LabelInfo> tabsList) {
		super(fm);
		initData(tabsList);
	}

	public void initData(List<LabelInfo> tabsList) {
		// TODO Auto-generated method stub
		this.tabsList = tabsList;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		// return channelList.get(position).getName();
		return tabsList.get(position).name;
	}

	@Override
	public int getCount() {
		// return channelList.size();
		return tabsList.size();
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		// TODO Auto-generated method stub
		return super.instantiateItem(container, position);
	}

	@Override
	public Fragment getItem(int position) {
		return getFragment(position);
	}

	@Override
	public int getItemPosition(Object object) {
		// TODO Auto-generated method stub
		return POSITION_NONE;
	}

	private Fragment getFragment(int position) {

		LabelInfo labelInfo = tabsList.get(position);
		int type = Integer.valueOf(labelInfo.type);
		
		if (labelInfo.name.equals("全网热点")) {
			return HotFragment.newInstance(labelInfo.url, labelInfo.id);
		}else if(labelInfo.name.equals("软件推荐")) {
			return SoftFragment.newInstance(labelInfo.url);
		}else if(CHANNEL_COMMON == type){
			return CommonFragment.newInstance(labelInfo.url, labelInfo.id);
		}else if(CHANNEL_HORIZONTAL == type){
			return GridModeFragment.newInstance(type,labelInfo.url, labelInfo.id);
		}else if(CHANNEL_LIVE == type){
			return LiveFragment.newInstance(labelInfo.url, labelInfo.id);
		}else if(CHANNEL_VERTICAL == type){
			return GridModeFragment.newInstance(type,labelInfo.url, labelInfo.id);
//			return VerticalFragment.newInstance(labelInfo.url, labelInfo.id);
		}else if(CHANNEL_VIP == type){
			return VipFragment.newInstance(labelInfo.url, labelInfo.id);
		}else if(CHANNEL_COLUMN == type){
			return ColumnFragment.newInstance(labelInfo.url, labelInfo.id);
		}else if(CHANNEL_LEADERBOARD == type){
			return LeaderboardFragment.newInstance(labelInfo.url, labelInfo.id);
		}else{
			return CommonFragment.newInstance(labelInfo.url, labelInfo.id);
		}
		

//		switch (Integer.valueOf(labelInfo.type)) {
//		case CHANNEL_COMMON:
//			
//		case CHANNEL_HORIZONTAL:
//			
//		case CHANNEL_LIVE:
//			
//		case CHANNEL_VERTICAL:
//			return VerticalFragment.newInstance(labelInfo.url);
//		case CHANNEL_VIP:
//			
//		default:
//			break;
//		}

		/*
		 * String channelName = channelList.get(position).getName();
		 * if(channelName.equals("全网热点")){ return new HotFragment() } else
		 * if(channelName.equals("直播")){ return new LiveFragment(); } else
		 * if(channelName.equals("栏目")){ return new ColumnFragment(); } else
		 * if(channelName.equals("横版")){ return new HorizontalFragment(); } else
		 * if(channelName.equals("竖版")){ return new VerticalFragment(); } else
		 * if(channelName.equals("VIP影院")){ return new VipFragment(); } else
		 * if(channelName.equals("通用")){ return new CommonFragment(); } else
		 * if(channelName.equals("软件推荐")){ return new SoftFragment(); }
		 */

//		return null;
	}

}
